﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TestWebApplication.CommerceAccount;
using Microsoft.Commerce.Proxy.AccountService;
using TestWebApplication.CommerceTestDataProvider;
using System.Xml;
using System.IO;
using System.Security;
using System.Security.Cryptography.X509Certificates;

namespace TestWebApplication
{
    public partial class Login : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            
            String fileLocation = HttpContext.Current.Server.MapPath(Constants.CountriesLocation);            
            fileLocation=fileLocation.Remove(fileLocation.IndexOf(ServiceSettings.Api),ServiceSettings.Api.Length+1);
            XmlDocument xml = new XmlDocument();
            xml.Load(fileLocation);
            XmlElement root = xml.DocumentElement;
            foreach (XmlNode countryNode in root.ChildNodes)
            {
                countries.Items.Add(new ListItem()
                {
                    Text = countryNode.Attributes["name"].Value,
                    Value = countryNode.Attributes["value"].Value
                });
            }
        }

        protected void login2_Click(object sender, EventArgs e)
        {
            Session["locale"] = countries.SelectedValue;

            AccountInfo account = AccountHandler.getAccount(puid.Text, liveID.Text);
            
            Session["accountID"] = account.AccountID;
            Session["requester"] = AccountHandler.identity;

            //Response.Redirect("<script>window.open('www.baidu.com');</script>");
            Response.Redirect("MainPage.aspx");
        }

        protected void loginPartner_Click(object sender, EventArgs e)
        {
            Response.Redirect("ShowPurchases.aspx");
        }
    }
}
